{include file="public/header" /}
<link rel="stylesheet" type="text/css" href="/static/admin/webupload/webuploader.css">
<link rel="stylesheet" type="text/css" href="/static/admin/webupload/style.css">
<style>
    .file-item{float: left; position: relative; width: 110px;height: 110px; margin: 0 20px 20px 0; padding: 4px;}
    .file-item .info{overflow: hidden;}
    .uploader-list{width: 100%; overflow: hidden;}
</style>
<body class="gray-bg">
<div class="wrapper wrapper-content animated fadeInRight">
    <div class="row">
        <div class="col-sm-12">
            <div class="ibox float-e-margins">
                <div class="ibox-title">
                    <h5>编辑公告</h5>
                </div>
                <div class="ibox-content">
                    <form class="layui-form layui-form-pane" name="edit" id="edit" method="post" action="">
                        <input type="hidden" name="id" value="{$article.id}">
                        <div class="layui-form-item">
                            <label class="layui-form-label">标题：</label>
                            <div class="layui-input-block">
                                <input id="title" type="text" class="layui-input" lay-verify="required" lay-verType="tips" name="title" value="{$article.title}">
                            </div>
                        </div>
                        <div class="hr-line-dashed"></div>
                        <div class="layui-form-item">
                            <label class="layui-form-label">所属分类：</label>
                            <div class="layui-input-inline">
                                <select class="layui-input" name="cate_id"  lay-verify="required" lay-verType="tips">
                                    <option value="">==请选择==</option>
                                    {if !empty($cate)}
                                    {foreach name="cate" item="vo"}
                                    <option value="{$vo.id}" {if condition="$article['cate_id'] eq $vo['id']"}selected{/if}>{$vo.name}</option>
                                    {/foreach}
                                    {/if}
                                </select>
                            </div>
                        </div>
                        <div class="hr-line-dashed"></div>
                        <div class="layui-form-item">
                            <label class="layui-form-label">关键字：</label>
                            <div class="layui-input-block">
                                <input id="keyword" type="text" class="layui-textarea" name="keyword" value="{$article.keyword}">
                            </div>
                        </div>
                        <div class="hr-line-dashed"></div>
                        <div class="layui-form-item">
                            <label class="layui-form-label">描述：</label>
                            <div class="layui-input-block">
                                <textarea type="text" name="remark" id="remark" placeholder="输入文章描述" class="layui-textarea">{$article.remark}</textarea>
                            </div>
                        </div>
                        <div class="hr-line-dashed"></div>
                        <div class="layui-form-item">
                            <label class="layui-form-label">封面：</label>
                            <div class="layui-input-block">
                                <input type="hidden" id="data_photo" name="photo" value="{$article.photo}">
                                <div id="fileList" class="uploader-list" style="float:right"></div>
                                <div id="imgPicker" style="float:left">选择图片</div>
                                <img id="img_data" height="100px" style="float:left;margin-left: 50px;margin-top: -10px;" onerror="this.src='/static/admin/images/no_img.jpg'" src="/static/uploads/images/{$article.photo}"/>
                            </div>
                        </div>
                        <div class="hr-line-dashed"></div>
                        <div class="layui-form-item">
                            <label class="layui-form-label " for="myEditor">内容：</label>
                            <div class="layui-input-block">
                                <script src="/static/admin/ueditor/ueditor.config.js" type="text/javascript"></script>
                                <script src="/static/admin/ueditor/ueditor.all.js" type="text/javascript"></script>
                                <textarea name="content" style="width:100%" id="myEditor" lay-verify="required" lay-verType="tips">{$article.content}</textarea>
                                <script type="text/javascript">
                                    var editor = new UE.ui.Editor();
                                    editor.render("myEditor");
                                </script>
                            </div>
                        </div>
                        <div class="hr-line-dashed"></div>
                        <div class="layui-form-item">
                            <label class="layui-form-label">是否推荐：</label>
                            <div class="layui-input-block">
                                    {if condition="$article['is_tui'] eq 1 "}
                                    <input type="radio" name='is_tui' value="1" checked="checked" title="是"/>&nbsp;&nbsp;
                                    <input type="radio" name='is_tui' value="0" title="否"/>
                                    {else/}
                                    <input type="radio" name='is_tui' value="1" title="是"/>&nbsp;&nbsp;
                                    <input type="radio" name='is_tui' value="0" checked="checked" title="否"/>
                                    {/if}
                            </div>
                        </div>
                        <div class="hr-line-dashed"></div>
                        <div class="layui-form-item">
                            <label class="layui-form-label">状&nbsp;态：</label>
                            <div class="layui-input-block">
                                    <input type="radio" name='status' value="1" title="开启" {if condition="$article['status'] eq 1 "}checked{/if}/>&nbsp;&nbsp;
                                    <input type="radio" name='status' value="0" title="关闭" {if condition="$article['status'] eq 0 "}checked{/if}/>
                            </div>
                        </div>
                        <div class="hr-line-dashed"></div>
                        <div class="layui-form-item">
                            <label class="layui-form-label">访问量：</label>
                            <div class="layui-input-inline">
                                <input type="text" name="views" id="views" value="1" class="layui-input" value="{$article.views}">
                            </div>
                        </div>
                        <div class="hr-line-dashed"></div>
                        <div class="layui-form-item">
                            <label class="layui-form-label">作者：</label>
                            <div class="layui-input-inline">
                                <input type="text" name="writer" id="writer" class="layui-input" value="{$article.writer}">
                            </div>
                        </div>
                        <div class="hr-line-dashed"></div>
                        <div class="layui-form-item">
                            <div class="layui-input-inline">
                                <button class="btn btn-primary" type="submit" lay-submit lay-filter="edit_article"><i class="fa fa-save"></i> 保存</button>&nbsp;&nbsp;&nbsp;
                                <a class="btn btn-danger" href="javascript:history.go(-1);"><i class="fa fa-close"></i> 返回</a>
                            </div>
                        </div>
                    </form>
                </div>
            </div>

        </div>
    </div>
</div>
{include file="public/footer" /}

<script type="text/javascript" src="/static/admin/webupload/webuploader.min.js"></script>

<script type="text/javascript">
    var $list = $('#fileList');
    //上传图片,初始化WebUploader
    var uploader = WebUploader.create({

        auto: true,// 选完文件后，是否自动上传。
        swf: '/static/admin/js/webupload/Uploader.swf',// swf文件路径
        server: "{:url('Upload/upload')}",// 文件接收服务端。
        duplicate :true,// 重复上传图片，true为可重复false为不可重复
        pick: '#imgPicker',// 选择文件的按钮。可选。

        accept: {
            title: 'Images',
            extensions: 'gif,jpg,jpeg,bmp,png',
            mimeTypes: 'image/jpg,image/jpeg,image/png'
        },

        'onUploadSuccess': function(file, data, response) {
            $("#data_photo").val(data._raw);
            $("#img_data").attr('src', '/static/uploads/images/' + data._raw).show();
        }
    });

    uploader.on( 'fileQueued', function( file ) {
        $list.html( '<div id="' + file.id + '" class="item">' +
            '<h4 class="info">' + file.name + '</h4>' +
            '<p class="state">正在上传...</p>' +
            '</div>' );
    });

    // 文件上传成功
    uploader.on( 'uploadSuccess', function( file ) {
        $( '#'+file.id ).find('p.state').text('上传成功！');
    });

    // 文件上传失败，显示上传出错。
    uploader.on( 'uploadError', function( file ) {
        $( '#'+file.id ).find('p.state').text('上传出错!');
    });




    $(function(){
        var form = layui.form;
        form.on('submit(edit_article)',function (data) {
            var data = data.field;
            if( !data.cate_id){
                layer.msg('请选择分类', {icon: 5,time:1500,shade: 0.1}, function(index){
                    layer.close(index);
                });
                return false;
            }
            $.post("{:url('edit_article')}",data,function (result) {
                if(result.code == 1){
                    layer.msg(result.msg, {icon: 6,time:1500,shade: 0.1}, function(index){
                        layer.close(index);
                        window.location.href="{:url('article/index')}";
                    });
                }else{
                    layer.msg(result.msg, {icon: 5,time:1500,shade: 0.1}, function(index){
                        layer.close(index);
                    });
                    return false;
                }
            });
            return false;
        });

    });

</script>
</body>
</html>
